package com.atguigu.tingshu.user.api;

import com.alibaba.fastjson2.JSONObject;
import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserListenProcess;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

    @Autowired
    private UserListenProcessService userListenProcessService;

    // http://127.0.0.1:8500/api/user/userListenProcess/getTrackBreakSecond/20313
    // 查询声音的 播放进度 // 去mongoDb 查询
    // 返回 播放进度秒数
    @GuiguLogin
    @RequestMapping("getTrackBreakSecond/{trackId}")
    public Result getTrackBreakSecond(@PathVariable("trackId") Long trackId) {
        BigDecimal breakSecond = userListenProcessService.getTrackBreakSecond(trackId);
        return Result.ok(breakSecond);
    }
    // 更新声音的进度
    // ttp://127.0.0.1:8500/api/user/userListenProcess/updateListenProcess
    // 前端上传 trackId  albumId breakSecond
    @GuiguLogin
    @RequestMapping("updateListenProcess")
    public Result updateListenProcess(@RequestBody UserListenProcessVo UserListenProcessVo) {
        userListenProcessService.updateListenProcess(UserListenProcessVo);
        return Result.ok();
    }

    // ttp://127.0.0.1:8500/api/user/userListenProcess/getLatelyTrack
    // 查询用户最近播放声音信息
    @GuiguLogin
    @Operation(summary = "查询用户最近播放声音的id")
    @RequestMapping("getLatelyTrack")
    public Result getLatelyTrack() {
        JSONObject jsonObject = userListenProcessService.getLatelyTrack();
        return Result.ok(jsonObject);
    }

}

